// 树状数组范围增加、范围查询模版
// 测试链接 : https://www.luogu.com.cn/problem/P3372
// 提交以下的code，可以直接通过

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100001;
// 维护原始数组的差分信息：Di
long info1[MAXN];
// 维护原始数组的差分加工信息：(i-1) * Di
long info2[MAXN];
int n, m;

inline long read()
{
    char ch = getchar();
    long x = 0, f = 1;
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = 10 * x + ch - '0';
        ch = getchar();
    }
    return f * x;
}

int lowbit(int i)
{
    return i & -i;
}

void add(long* tree, int i, long v)
{
    while(i <= n)
    {
        tree[i] += v;
        i += lowbit(i);
    }
}

long sum(long* tree, int i)
{
    long ans = 0;
    while(i > 0)
    {
        ans += tree[i];
        i -= lowbit(i);
    }
    return ans;
}

// 原始数组中[l..r]每个数值+v
void add(int l, int r, long v)
{
    add(info1, l, v);
    add(info1, r + 1, -v);
    add(info2, l, (l - 1) * v);
    add(info2, r + 1, -(r * v));
}

// 原始数组中[l..r]范围上的累加和
long range(int l, int r)
{
    return sum(info1, r) * r - sum(info2, r) - sum(info1, l - 1) * (l - 1) + sum(info2, l - 1);
}

int main()
{
    n = read(), m = read();
    long cur;
    for(int i = 1; i <= n; ++i)
    {
        cur = read();
        add(i, i, cur);
    }
    long v;
    for(int i = 1, op, l, r; i <= m; ++i)
    {
        op = read();
        if(op == 1)
        {
            l = read();
            r = read();
            v = read();
            add(l, r, v);
        }
        else
        {
            l = read();
            r = read();
            printf("%ld\n", range(l, r));
        }
    }

    return 0;
}